package IOStreamStudy.fileCopy;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 将a.txt文件中的内容复制到b.txt中
 * */

public class fileCopyDemo {

    @Test
    public void fileCopy01() throws IOException {
        int len;
        byte[] buffer = new byte[15];// 读取的缓冲区
        // 读取的文件
        String readFile = "D:\\all_projects\\java_projects\\java_ij\\springMVC" +
                "\\NetWork\\src\\cn\\usts\\edu\\IOStreamStudy\\fileCopy\\a.txt";
        // 写入的文件
        String writeFile = "D:\\all_projects\\java_projects\\java_ij\\springMVC" +
                "\\NetWork\\src\\cn\\usts\\edu\\IOStreamStudy\\fileCopy\\b.txt";

        FileInputStream fileInputStream = new FileInputStream(readFile);

        FileOutputStream fileOutputStream = new FileOutputStream(writeFile);


        while ((len = fileInputStream.read(buffer))!=-1){
            fileOutputStream.write(buffer,0,len);
            System.out.println(new String(buffer,0,len));
            System.out.println(len);// 一个换行是2byte
        }

        // 关闭流
        fileOutputStream.close();
        fileInputStream.close();


    }
}
